import init, { 
    WasmActorSystem, 
    WasmActor, 
    init_panic_hook, 
    create_props 
} from '../pkg/protoactor_rs';

async function main() {
    // Initialize the WASM module
    await init();
    init_panic_hook();

    // Create an actor system
    const system = new WasmActorSystem();

    // Create actor props
    const props = create_props(() => new WasmActor());

    // Spawn an actor
    const pid = await system.spawn(props);
    console.log('Actor spawned with PID:', pid);

    // Send a message to the actor
    const message = { type: 'greet', name: 'World' };
    await system.send(pid, message);

    // Make a request and wait for response
    const response = await system.request(pid, message, 5000);
    console.log('Received response:', response);
}

main().catch(console.error); 